function clearTxt(){
	$('#txtTableName').val('');
	$("#txtTableDesc").val('');
	$("#hidTableNameValue").val("0");
	$("#txtWarnTableName").text("");
}

function add(){
	if($("#hidTableNameValue").val() == "1"){
		alert("数据库存在该表，请重新设计表名");
		return;
	}

	var tableName = $('#txtTableName').val();
	if(tableName == ""){
		alert("表名不能为空！");
		return;
	}
	
	var tableDesc = $("#txtTableDesc").val();
	if(tableDesc == ""){
		alert("表说明不能为空！");
		return;
	}
	
	var tableInfo = {}; //表信息
	tableInfo.tableName = tableName;
	tableInfo.tableDesc = tableDesc;	
	tableInfo.createUser = $("#txtTableDesc").val();	
	tableInfo.database = "autotable";
	var jsonData = JSON.stringify(tableInfo);
	$.ajax({
		type : 'post',
		dataType : 'json',
		contentType : "application/json",
		data : jsonData,
		async : false,
		url : "../../sti.do?action=0",
		success : function(result) {
			if(result=="1"){
				$('#txtTableName').val('');
				$("#txtTableDesc").val('');
				$("#hidTableNameValue").val("0");
				alert("添加成功!");
				window.location.href="tableInfo.jsp";
			}else{
				alert("添加失败!");
			}
		}
	});
}

function returnHome(){
	window.location.href="tableInfo.jsp";
}

function validateExist(){
	if($('#txtTableName').val() == ""){
		$("#txtWarnTableName").text("请设计表名！").css("color", "rgba(218, 82, 82, 0.89)").css("font-size","14px");
		return;
	}
	
	var tableName = $("#txtTableName").val();
	$.ajax({
		type : 'get',
		dataType : 'json',
		contentType : "application/json",
		async : false,
		url : "../../sti.do?action=1&tableName="+tableName,
		success : function(result) {
			if(result=="1"){
				$("#hidTableNameValue").val("1");
				$("#txtWarnTableName").text("数据库存在该表，请重新设计表名！").css("color", "rgba(218, 82, 82, 0.89)").css("font-size","14px");
			}else{
				$("#hidTableNameValue").val("0");
				$("#txtWarnTableName").text("ok!").css("color", "#47a447").css("font-size","16px").css("font-weight", "bold");
			}
		}
	});
}

function clearTableName(){
	$("#txtWarnTableName").text("");
}